<?php

class Util_Logic {
	
	static public function isIn($needle,$array){
		foreach($array as $el){
			if ($needle == $el)return true;
		}
		return false;
	}
	
	static public function allGood($array){
		if(is_array($array)){
			foreach($array as $t){
				if($t!=true)return false;
			}
			return true;
		} else {
			return $array?true:false;
		}
	}
	
	static public function allAre($val, $array){
		foreach($array as $t){
			if($t!==$val)return false;
		}
		return true;
	}
	
	static public function allNumeric($array){
		foreach($array as $el){
			if(!is_numeric($el))return false;
		}
		return true;
	}
	
	static public function compareHashVals($home_array,$away_array,$attr_array,$compareType = 'all_equal'){
		switch ($compareType){
			case 'all_equal':
				foreach ($attr_array as $attr){
					if($home_array[$attr]!=$away_array[$attr])return false;
				}
				return true;
				break;
			default: break;
		} 
	}
	
	/**
	 * Zwaraca true jeśli obiekt jest stworzeniem jednej z klas
	 * @param object $obj
	 * @param array $classes
	 */
	static public function isInstance($obj,array $classes){
		foreach($classes as $class){
			if($obj instanceof $class){return true;}
		}
		return false;
	}
	
	static public function isAjax(){
		$key = 'HTTP_X_REQUESTED_WITH';$match = 'xmlhttprequest';
		return !empty($_SERVER[$key]) && strtolower($_SERVER[$key]) == $match;
	}
	
	// sprawdza czy parametr zdefiniowany w arrayu i czy nie jest pustym stringiem
	static public function rqTest($param){ 
		$rq = Zend_Controller_Front::getInstance()->getRequest();
		return ($rq->getParam($param) && $rq->getParam($param)!='');
	}
		
}